/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FrmEstudiantes.java
 *
 * Created on 2/11/2012, 04:10:26 PM
 */

package co.edu.unitecnologica.interfaz;

import co.edu.unitecnologica.modelo.Estudiantes;
import co.edu.unitecnologica.modelo.EstudiantesPK;
import co.edu.unitecnologica.modelo.Periodos;
import co.edu.unitecnologica.modelo.Programas;
import co.edu.unitecnologica.modelo.TiposEstudiantes;
import co.edu.unitecnologica.reportes.AdmReportes;
import java.util.Calendar;
import java.util.List;
import javax.persistence.Query;
import javax.swing.JOptionPane;

/**
 *
 * @author osalcedo
 */
public class FrmEstudiantes extends Formulario {

    private Object[] periodos;

    /** Creates new form FrmEstudiantes */
    public FrmEstudiantes(Principal p) {
        super(p);
        initComponents();
        init();
        habilitarCampos(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jmiConceptosEstudiantes = new javax.swing.JMenuItem();
        jmiGenerarLiquidacion = new javax.swing.JMenuItem();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jtfId = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jtfCodTelnet = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jtfNombres = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jtfApellidos = new javax.swing.JTextField();
        jcbTipoDocumento = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jtfNumero = new javax.swing.JTextField();
        jcbTipoEstudiante = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        jcbEstado = new javax.swing.JComboBox();
        jcbProgramas = new javax.swing.JComboBox();
        jtfExpedicion = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jtfPeriodoIngreso = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();

        jmiConceptosEstudiantes.setText("Administrar Conceptos de liquidacion a estudiantes");
        jmiConceptosEstudiantes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiConceptosEstudiantesActionPerformed(evt);
            }
        });

        jmiGenerarLiquidacion.setText("Generar Liquidación");
        jmiGenerarLiquidacion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiGenerarLiquidacionActionPerformed(evt);
            }
        });

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("Estudiantes");

        jLabel1.setText("ID:");

        jLabel2.setText("Cod Telnet:");

        jLabel3.setText("Nombres:");

        jLabel4.setText("Apellidos:");

        jcbTipoDocumento.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "TI", "CC", "CE", "PASAPORTE" }));

        jLabel5.setText("Tipo de documento:");

        jLabel6.setText("Numero:");

        jLabel7.setText("Tipo de estudiante:");

        jcbEstado.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "AS-Estudiante Activo", "IS - Estudiante Inactivo", "IG - Estudiante Inactivo debido a graduación" }));

        jLabel8.setText("Expedicion:");

        jLabel9.setText("Programa:");

        jLabel10.setText("Periodo Ingreso:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel6)
                    .addComponent(jLabel4)
                    .addComponent(jLabel3)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1)
                    .addComponent(jLabel5)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jtfApellidos)
                        .addComponent(jtfNombres, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jtfId)
                        .addComponent(jtfCodTelnet))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jcbEstado, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jcbTipoEstudiante, javax.swing.GroupLayout.Alignment.LEADING, 0, 134, Short.MAX_VALUE))
                    .addComponent(jcbProgramas, javax.swing.GroupLayout.PREFERRED_SIZE, 256, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jcbTipoDocumento, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jtfPeriodoIngreso, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jtfExpedicion, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jtfNumero, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jtfId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jcbProgramas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jtfCodTelnet, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jtfNombres, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jtfApellidos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfPeriodoIngreso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jcbTipoDocumento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jtfNumero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jtfExpedicion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jcbTipoEstudiante, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jcbEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(14, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jmiGenerarLiquidacionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiGenerarLiquidacionActionPerformed
        if(principal.validarObjeto("gen_liquidacion")){
            Estudiantes e=(Estudiantes) lista.get(this.getRegistroActual());
            Object periodo=javax.swing.JOptionPane.showInternalInputDialog(
                    this,
                    "Seleccione el periodo:",
                    "Generar liquidación",
                    JOptionPane.QUESTION_MESSAGE,
                    this.frameIcon,
                    periodos,
                    periodos[periodos.length-1]
                    );
            int resultado;
            if(periodo!=null){
                String sql="select f_liquidar('"
                                +e.getEstudiantesPK().getId()+"','"
                                +e.getEstudiantesPK().getCodPrograma()+"','"
                                +periodo.toString().split("-")[0]+"','"
                                +principal.getUsuario().getUsuario()+"') from dual";
                Query q=em.createNativeQuery(sql);
                Object salida=q.getSingleResult();
                if(salida.toString().equals("1")){
                    resultado=JOptionPane.showInternalConfirmDialog(this, "Estudiante liquidado en forma exitosa\n " +
                            "desea imprimir dicho comprobante");
                    if(resultado==JOptionPane.OK_OPTION){
                        em.getTransaction().begin();
                        java.sql.Connection connection = em.unwrap(java.sql.Connection.class);
                        AdmReportes reporte= new AdmReportes(connection);
                        reporte.imprimirComprobanteEstudiante(e.getEstudiantesPK().getId(), periodo.toString().split("-")[0]);
                        em.getTransaction().commit();
                    }
                }
                else
                    JOptionPane.showInternalMessageDialog(this, "Error en el proceso de liquidación");
            }
            else{
                System.out.println("cancelado por el usuario");
            }
        }
        else
            JOptionPane.showMessageDialog(this, "Usuario no está autorizado para realzar esta acción");
    }//GEN-LAST:event_jmiGenerarLiquidacionActionPerformed

    private void jmiConceptosEstudiantesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiConceptosEstudiantesActionPerformed
        if(principal.validarObjeto("FrmConceptosEstudiantes")){
            FrmConceptosEstudiantes ce= new FrmConceptosEstudiantes(principal,(Estudiantes) lista.get(this.getRegistroActual()));
            principal.getEscritorio().add(ce);
            ce.setVisible(true);
        }
        else
            JOptionPane.showMessageDialog(menuOpciones, "Usuario no tiene privilegios para acceder a este objeto");

    }//GEN-LAST:event_jmiConceptosEstudiantesActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JComboBox jcbEstado;
    private javax.swing.JComboBox jcbProgramas;
    private javax.swing.JComboBox jcbTipoDocumento;
    private javax.swing.JComboBox jcbTipoEstudiante;
    private javax.swing.JMenuItem jmiConceptosEstudiantes;
    private javax.swing.JMenuItem jmiGenerarLiquidacion;
    private javax.swing.JTextField jtfApellidos;
    private javax.swing.JTextField jtfCodTelnet;
    private javax.swing.JTextField jtfExpedicion;
    private javax.swing.JTextField jtfId;
    private javax.swing.JTextField jtfNombres;
    private javax.swing.JTextField jtfNumero;
    private javax.swing.JTextField jtfPeriodoIngreso;
    // End of variables declaration//GEN-END:variables

    @Override
    public boolean insertarRegistro() {
        try{
            em.getTransaction().begin();
            Estudiantes t= new Estudiantes();
            EstudiantesPK pk=new EstudiantesPK();
            pk.setCodPrograma(Integer.parseInt(this.jcbProgramas.getSelectedItem().toString().split("-")[0]));
            pk.setId(this.jtfId.getText());
            t.setEstudiantesPK(pk);
            t.setApellidos(this.jtfApellidos.getText());
            t.setNombres(this.jtfNombres.getText());
            t.setCodTelnet(this.jtfCodTelnet.getText());
            Periodos p= em.getReference(Periodos.class, Integer.parseInt(jtfPeriodoIngreso.getText()));
            t.setCodPeriodoIngreso(p);
            TiposEstudiantes te= em.getReference(TiposEstudiantes.class, jcbTipoEstudiante.getSelectedItem().toString().split("-")[0]);
            t.setCodTipoEstudiante(te);
            t.setTipoDocumento(this.jcbTipoDocumento.getSelectedItem().toString());
            t.setDocumento(this.jtfNumero.getText());
            t.setExpedicion(this.jtfExpedicion.getText());
            t.setEstado(this.jcbEstado.getSelectedItem().toString().split("-")[0]);
            t.setFechaActividad(Calendar.getInstance().getTime());
            t.setHoraActividad(Calendar.getInstance().getTime());
            t.setUsuario(principal.getUsuario().getUsuario());
            em.persist(t);
            em.getTransaction().commit();
            return true;
        }catch(Exception e){
            JOptionPane.showMessageDialog(this, e.getLocalizedMessage());
            em.getTransaction().rollback();
            return false;
        }
    }

    @Override
    public boolean buscarRegistros() {
         try{
            String sql="SELECT t.* "
                    + " FROM estudiantes t"
                    + " WHERE "
                    + "     t.id like '%"+jtfId.getText()+"%' "
                    + "     and t.cod_telnet like '%"+jtfCodTelnet.getText()+"%' "
                    + "     and upper(t.apellidos) like upper('%"+this.jtfApellidos.getText()+"%') "
                    + "     and upper(t.nombres) like upper('%"+this.jtfNombres.getText()+"%') "
                    + "     and t.documento like '%"+this.jtfNumero.getText()+"%' ";
            if(!jcbProgramas.getSelectedItem().toString().isEmpty())
                sql+="     and t.cod_programa ='"+jcbProgramas.getSelectedItem().toString().split("-")[0]+"'";
            query = em.createNativeQuery(sql,Estudiantes.class);
            lista= query.getResultList();
            this.setRegistroActual(0);
            this.setRegistrosTotales(lista.size());
            this.mostrarRegistro(getRegistroActual());
            return true;
        }catch(Exception e){
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public boolean editarRegistro() {
        try{
            em.getTransaction().begin();
            Estudiantes t= (Estudiantes) lista.get(getRegistroActual());
            EstudiantesPK pk=new EstudiantesPK();
            pk.setCodPrograma(Integer.parseInt(this.jcbProgramas.getSelectedItem().toString().split("-")[0]));
            pk.setId(this.jtfId.getText());
            t.setEstudiantesPK(pk);
            t.setApellidos(this.jtfApellidos.getText());
            t.setNombres(this.jtfNombres.getText());
            t.setCodTelnet(this.jtfCodTelnet.getText());
            TiposEstudiantes te= em.getReference(TiposEstudiantes.class, jcbTipoEstudiante.getSelectedItem().toString().split("-")[0]);
            t.setCodTipoEstudiante(te);
            Periodos p= em.getReference(Periodos.class, Integer.parseInt(jtfPeriodoIngreso.getText()));
            t.setCodPeriodoIngreso(p);
            t.setTipoDocumento(this.jcbTipoDocumento.getSelectedItem().toString());
            t.setDocumento(this.jtfNumero.getText());
            t.setExpedicion(this.jtfExpedicion.getText());
            t.setEstado(this.jcbEstado.getSelectedItem().toString().split("-")[0]);
            t.setFechaActividad(Calendar.getInstance().getTime());
            t.setHoraActividad(Calendar.getInstance().getTime());
            t.setUsuario(principal.getUsuario().getUsuario());
            em.getTransaction().commit();
            return true;
        }catch(Exception e){
            em.getTransaction().rollback();
            return false;
        }
    }

    @Override
    public boolean borrarRegistro() {
        try{
            em.getTransaction().begin();
            Estudiantes t= (Estudiantes) lista.get(getRegistroActual());
            em.remove(t);
            em.getTransaction().commit();
            return true;
        }catch(Exception e){
            em.getTransaction().rollback();
            return false;
        }
    }

    @Override
    public void cargarRegistros() {
        query=em.createNamedQuery("Estudiantes.findAll");
        lista=query.getResultList();
        setRegistroActual(0);
        setRegistrosTotales(lista.size());
        mostrarRegistro(getRegistroActual());
    }

    @Override
    public void limpiarCampos() {
        jtfApellidos.setText("");
        jtfCodTelnet.setText("");
        jtfExpedicion.setText("");
        jtfId.setText("");
        jtfNombres.setText("");
        jtfNumero.setText("");
        jtfPeriodoIngreso.setText("");
    }

    @Override
    public void habilitarCampos(boolean v) {
        this.jtfApellidos.setEditable(v);
        this.jtfCodTelnet.setEditable(v);
        this.jtfExpedicion.setEditable(v);
        this.jtfId.setEditable(v);
        this.jtfNombres.setEditable(v);
        this.jtfNumero.setEditable(v);
        this.jtfPeriodoIngreso.setEditable(v);
        this.jcbEstado.setEditable(v);
        this.jcbProgramas.setEditable(v);
        this.jcbTipoDocumento.setEditable(v);
        this.jcbTipoEstudiante.setEditable(v);
    }

    @Override
    public void agregarItemsMenuOpciones() {
        this.principal.getJmOpciones().add(jmiConceptosEstudiantes);
        this.principal.getJmOpciones().add(jmiGenerarLiquidacion);
    }

    @Override
    public void mostrarRegistro(int r) {
         if(lista.size()>0 && r<lista.size()){
            Estudiantes t=(Estudiantes) lista.get(r);
            Programas p;
            if(t.getProgramas()==null)
                p=em.getReference(Programas.class, t.getEstudiantesPK().getCodPrograma());
            else
                p=t.getProgramas();
            this.jcbProgramas.setSelectedItem(p.getCod()+"-"+p.getDescripcion());
            this.jtfId.setText(t.getEstudiantesPK().getId());
            this.jtfApellidos.setText(t.getApellidos());
            this.jtfNombres.setText(t.getNombres());
            this.jtfCodTelnet.setText(t.getCodTelnet());
            this.jcbTipoEstudiante.setSelectedItem(t.getCodTipoEstudiante().getCod()+"-"+t.getCodTipoEstudiante().getDescripcion());
            this.jcbTipoDocumento.setSelectedItem(t.getTipoDocumento());
            this.jtfNumero.setText(t.getDocumento());
            this.jtfExpedicion.setText(t.getExpedicion());
            this.jcbEstado.setSelectedItem(t.getEstado());
            this.jtfPeriodoIngreso.setText(t.getCodPeriodoIngreso().getCod().toString());
        }
         else
             System.out.println("entrada invalida r="+r+", size="+lista.size());
    }

    private void init() {
        javax.persistence.Query q=em.createNamedQuery("TiposEstudiantes.findAll");
        List l=q.getResultList();
        for(int i=0;i<l.size();i++){
            TiposEstudiantes t= (TiposEstudiantes)l.get(i);
            jcbTipoEstudiante.addItem(t.getCod()+"-"+t.getDescripcion());
        }
        q=em.createNamedQuery("Programas.findAll");
        l=q.getResultList();
        jcbProgramas.addItem("");
        for(int i=0;i<l.size();i++){
            Programas t= (Programas)l.get(i);
            jcbProgramas.addItem(t.getCod()+"-"+t.getDescripcion());
        }
        String sql="select * from periodos where curdate() <= fecha_hasta";
        q=em.createNativeQuery(sql, Periodos.class);
        l=q.getResultList();
        periodos= new Object[l.size()];
        for(int i=0;i<l.size();i++)
            periodos[i]=new String(((Periodos)l.get(i)).getCod()+"-"+((Periodos)l.get(i)).getDescripcion());
    }

}
